//处理模型
const {
    successModel,
    failModel
} = require('../model/responseModel')

const {

    getCategoryDetail,
    getCategoryDetailGood,
} = require('../controller/category')


//处理分类相关的路由
const handleCategoryRoute = (req, res) => {
    //定义处理路由的逻辑
    const method = req.method;
    switch (method) {
        case 'GET': {

            // if (req.path === '/category') {
            //     //获取购物车数据
            //     return getCategory(req.query).then(data => {
            //         if (data) {
            //             return new successModel(data)
            //         } else {
            //             return new failModel('获取分类失败')
            //         }
            //     })
            // }

            // else 
            if (req.path === '/category/detail') {
                //获取购物车数据
                return getCategoryDetail().then(data => {
                    if (data) {
                        return new successModel(data)
                    } else {
                        return new failModel('获取分类详情失败')
                    }
                })
            }
            
           else if (req.path === '/category/detail/good') {
                //获取购物车数据
                return getCategoryDetailGood(req.query).then(data => {
                    if (data) {
                        return new successModel(data)
                    } else {
                        return new failModel('获取分类标签商品失败')
                    }
                })
            }
            else{
                return false;
            }
            
            
        };
    default: {
        return false;
    }
    }

}

module.exports = handleCategoryRoute